import sys
from __builtin__ import *
from vrOSGWidget import *
from vrScenegraph import *
from vrAEBase import *

script_dir = sys.argv[0]

# function alias
resetRift = resetOculusRiftOrientation
trackRift = setOculusRiftTracking


def clearNodes():
    noitom_root = findNode('NoitomRoot')
    if noitom_root.isValid():
        noitom_root.setTranslation(0, 0, 0)
        noitom_root.setRotation(0, 0, 0)

    noitom_cmd = findNode('noitom_cmd')
    if noitom_cmd.isValid():
        noitom_cmd.setTranslation(0, 0, 0)

    noitom_HMD = findNode('noitom_HMD')
    if noitom_HMD.isValid():
        noitom_HMD.setTranslation(0, 0, 1000)

    hmd_names = ["noitom_HMD" + str(n) for n in range(21)]
    hmd_names = hmd_names[1:]
    for name in hmd_names:
        hmd_node = findNode(name)
        if hmd_node.isValid():
            hmd_node.setTranslation(0, 0, -2000)

    ctrl_names = ["noitom_Controller" + str(n) for n in range(22)]
    ctrl_names = ctrl_names[1:]
    for name in ctrl_names:
        ctrl_node = findNode(name)
        if ctrl_node.isValid():
            ctrl_node.setTranslation(0, 0, -2000)


def initResource():
    # load(script_dir + "noitom_res.vpb")
    clearNodes()
    trackRift(True)
    resetRift()

    attach_node = findNode('AttachPnt')
    setCameraBeacon(-1, attach_node)

    print 'InitResource ok'


initResource()
